Hi,
pragma runLim,0
#include <utils/ole.inc>
#include <utils/doctools/itfutil.inc>
checkPlatform (NLS_("Microsoft Excel"))
const string mainChoices[] = {(NLS_("Ignore")),AHeading,AShortText, ALongText,(NLS_("Object Heading And Text"))}
const int mainIgnore = 0
const int mainHeading = 1
const int mainShort = 2
const int mainLong = 3
const int mainHeadingLong = 4
//--------------------------------------------------------------
OleAutoObj objExcel = null
OleAutoObj objWorkbooks = null
OleAutoObj objWorkbook = null
OleAutoObj objSheet = null
OleAutoObj objCell = null
OleAutoArgs args = create
//--------------------------------------------------------------
DB excelBox = null
DBE mainChoice, titleToggle
Trigger excelTrigger
Module m = current
bool includeColumnTitles = true
int noObjs = 0
void initProgress(DB forWin, Module m) {
Object o
noObjs = 0
for o in m do {
noObjs++
}
progressStart(forWin, LS_("String_Export_Progress",NLSTEMP_("Export Progress")), LS_("String_Exporting_1",NLSTEMP_("Exporting ")), noObjs)
}
void stepProgress(int objNo) {
progressStep objNo
progressMessage (dxlStrformat(LS_("String_Exporting_s_of_s",NLSTEMP_("Exporting %s of %s")), objNo (NLS_("")), noObjs (NLS_(""))) )
}
void preChecks() {
Object o = current
//Display a message when unable to read the object
if(!canRead o){
ack getExtMsg("String_Cannot_read_the_object",NLSTEMP_("Cannot read the object"))
halt
}
//If it is a main column attribute
string attributeName = o.(reserved AMainColumnAttribute)
if(!null attributeName)
{
if(!canRead o.attributeName)
{
ack dxlStrformat(getExtMsg("String_Cannot_read_s",NLSTEMP_("Cannot read %s")), ALongText)
halt
}
}
else
{
if (!canRead o.AHeading) {
ack dxlStrformat(getExtMsg("String_Cannot_read_s",NLSTEMP_("Cannot read %s")), AHeading)
halt
}
if (!canRead o.AShortText) {
ack dxlStrformat(getExtMsg("String_Cannot_read_s",NLSTEMP_("Cannot read %s")), AShortText)
halt
}
if (!canRead o.ALongText) {
ack dxlStrformat(getExtMsg("String_Cannot_read_s",NLSTEMP_("Cannot read %s")), ALongText)
halt
}
}
}
bool excelInit() {
objExcel = connectToApp(cObjExcelApplication, (NLS_("Excel")))
if (null objExcel) return false
makeVisible objExcel
// get workbooks collection
checkRes(oleGet(objExcel,cPropertyWorkbooks,objWorkbooks))
if (null objWorkbooks) {
ack getExtMsg("String_Unable_to_get_workbooks_collection",NLSTEMP_("Unable to get workbooks collection"))
return false
}
// add one
checkRes(oleMethod(objWorkbooks, cMethodAdd))
// get active workbook
checkRes(oleGet(objExcel,cPropertyActiveWorkbook,objWorkbook))
if (null objWorkbook) {
ack getExtMsg("String_Unable_to_get_active_workbook",NLSTEMP_("Unable to get active workbook"))
return false
}
// get active sheet
checkRes(oleGet(objWorkbook,cPropertyActiveSheet,objSheet))
if (null objSheet) {
ack getExtMsg("String_Unable_to_get_active_sheet",NLSTEMP_("Unable to get active sheet"))
return false
}
return true
}
string intToCol(int i) {
string s = (NLS_(""))
if ((i>=1) && (i<=256))
{
int d1 = (i-1) / 26
int d2 = (i-1) % 26
if (d1 > 0)
{
s = charOf( d1-1 + intOf('A')) (NLS_(""))
}
s = s charOf( d2 + intOf('A')) (NLS_(""))
}
else
{
if (i>256)
{
ack LS_("String_Too_many_columns",NLSTEMP_("Too many columns"))
}
else
{
ack dxlStrformat(getExtMsg("String_Invalid_column_reference_s",NLSTEMP_("Invalid column reference :%s")), i (NLS_("")))
}
halt
}
return (s)
}
Regexp dateCheck = regexp (NLS_("^([0-9]+-)+[0-9]+$"))
void setCell(int row, int col, string s) {
closeIfNonNull objCell
clear(args)
put(args, (intToCol col) row (NLS_("")))
checkRes(oleGet(objSheet, cMethodRange,args, objCell))
if (null objCell) {
ack getExtMsg("String_Unable_to_get_cell_object",NLSTEMP_("Unable to get cell object"))
halt
}
// Excel considers a string starting with the following characters:-
// An equal character (=), a plus character (+), a minus character (-) or the (@) character
// to be the start of an excel formula, hence it throws an error "OLE method failed".
// To avoid this we append "'" before the string.
// Also, "numbers-numbers" or "numbers-numbers-numbers" (Eg: 14-3, 14-10-17) will be intrepreted as "Date" in Excel.
// So we append "'" before those strings also.
if( s[0:0] == (NLS_("=")) || s[0:0] == (NLS_("+")) || s[0:0] == (NLS_("-")) || s[0:0] == (NLS_("@")) || dateCheck s )
{
s = (NLS_("'")) s
}
checkRes(olePut(objCell, cPropertyValue, s))
}
string headingLong(Object o) {
string headingStr = fullAttributeValue_(o,AHeading,false,false)
string textStr = fullAttributeValue_(o,ALongText,false,false)
if (null headingStr) {
return textStr
}
if (null textStr) {
return headingStr (NLS_(""))
}
return headingStr (NLS_("\n")) textStr (NLS_(""))
}
void doExcel(DB xx) {
Object o
Column c
string s
int doMain
int row = 0
int col
if (!excelInit) {
delete excelTrigger
return
}
doMain = get mainChoice
includeColumnTitles = get titleToggle
if (includeColumnTitles) {
col = 0
row++
for c in m do {
if ((main c) && (doMain == mainIgnore)) continue
col++
s = title c
if (s != (NLS_(""))) {
setCell(row, col, s)
}
}
}
initProgress(excelBox, m)
for o in m do {
col = 0
row ++
int rowExcludingTitle = 0
if (progressCancelled) break
if (includeColumnTitles) {
rowExcludingTitle = row - 1
stepProgress rowExcludingTitle
}
else
{
stepProgress row
}
for c in m do {
s = (NLS_(""))
col++
if (main c) {
//Check if the object is read locked
if (doMain == mainIgnore || !canRead o) {
col--
continue
}
string attributeName = o.(reserved AMainColumnAttribute)
if(null attributeName)
{
if (doMain == mainHeading) s = headingLong o //fullAttributeValue_(o,AHeading,false,false)
if (doMain == mainShort) s = headingLong o //o.AShortText (NLS_(""))
if (doMain == mainLong) s = headingLong o //fullAttributeValue_(o,ALongText,false,false)
if (doMain == mainHeadingLong) s = headingLong o
}
else
{ //Map the main column attribute to the Object text amd/or
//Object heading and text
if (doMain == mainLong || doMain == mainHeadingLong)
{
if(!hasCopyableTableAttributes(o))
{
continue
}
s = o.attributeName (NLS_(""))
}
}
} else {
if (null dxl(c)) {
s = probeAttrUSShortDate_(o, attrName c)
}
else {
s = text(c,o)
}
}
if (s != (NLS_(""))) {
setCell(row, col, s)
}
}
}
progressStop
disconnectFromApp objExcel
delete excelTrigger
}
bool closeModuleTrig(Trigger t) {
hide excelBox
return true
}
void closeDB(DB db) {
delete excelTrigger
hide excelBox
}
void makeBox() {
excelBox = centered LS_("String_Export_Excel",NLSTEMP_("Export Excel"))
excelTrigger = trigger(module, close, 10, closeModuleTrig)
mainChoice = choice(excelBox,LS_("String__Main_column",NLSTEMP_("'Main' column:")),mainChoices,mainHeadingLong, 30, false)
titleToggle = toggle(excelBox,LS_("String_Include_column_titles",NLSTEMP_("Include column titles")),includeColumnTitles)
ok(excelBox,LS_("String_Export",NLSTEMP_("Export")), doExcel)
help(excelBox, DOORSHelp, helpExportExcel)
close(excelBox, true, closeDB)
realize excelBox
}
//--------------------------------------------------------------------
// check status
if ((current Module) != null)
{
// check status
if ((current Object) != null)
{
preChecks
makeBox
show excelBox
}
else
{
ack LS_("String_There_are_no_objects_in_the_current_view",NLSTEMP_("There are no objects in the current view."))
}
}
else
{
ack LS_("String_There_is_no_current_module_to_export",NLSTEMP_("There is no current module to export."))
}
VBdo - Wed Feb 02 08:22:44 EST 2011 |
Re: simulate press export |
Re: simulate press export Paul Miller Melbourne, Australia |
Re: simulate press export Hope that helps, regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: simulate press export Mathias Mamsch - Wed Feb 02 19:15:33 EST 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: simulate press export Mathias Mamsch - Wed Feb 02 19:15:33 EST 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS Hi Mathias, The link "this post" appears to be broken. Can you advise? Thanks. Regards, Rudi
|
Re: simulate press export C2RW_Rudi_Rolih - Wed May 07 02:04:47 EDT 2014 Hi Mathias, The link "this post" appears to be broken. Can you advise? Thanks. Regards, Rudi
This post references some non broken links on this topic. I will repeat the links here with the new URLs: Maybe this will help, there are other posts on automating GUIs, if you search a bit you may find more. Regards, Mathias
|
Re: simulate press export Mathias Mamsch - Wed May 07 03:08:58 EDT 2014 This post references some non broken links on this topic. I will repeat the links here with the new URLs: Maybe this will help, there are other posts on automating GUIs, if you search a bit you may find more. Regards, Mathias
Thanks Mathias. |